package view.userinteface;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import view.controller.ControllerPrincipal;
import beans.BeanMarca;
import beans.BeanRodamiento;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class JInternalFrameAltaRodamiento extends javax.swing.JInternalFrame {
	private JButton btnCancelar;
	private JTextField txtMedida;
	private JLabel jLabel2;
	private JComboBox jComboMarcas;
	private JLabel jLabel1;
	private JTextField txtCaracteristica;
	private JTextField txtTipo;
	private JLabel lblCaracteristica;
	private JTextField txtCodigo;
	private JLabel lblMarca;
	private JLabel lblCodigo;
	private JButton btnAceptar;
	private ControllerPrincipal controllerPrincipal;
	private static JInternalFrameAltaRodamiento instancia;

	/**
	* Auto-generated main method to display this 
	* JInternalFrame inside a new JFrame.
	*/
		
	public static JInternalFrameAltaRodamiento getInstancia(){
		if (instancia==null){
			instancia = new JInternalFrameAltaRodamiento();
		}
		return instancia;
	}
	
	public JInternalFrameAltaRodamiento() {
		super();
		initGUI();
	}
	
    public void cargarMarcas (){
        List<BeanMarca> beanMarcas= controllerPrincipal.getInstancia().cargarComboMarcas();
        for (BeanMarca beanMarca:beanMarcas){
            this.jComboMarcas.addItem(beanMarca.toString());
        }
    }
	private void initGUI() {
		
		try {
			this.setPreferredSize(new java.awt.Dimension(420, 319));
			this.setBounds(0, 0, 420, 319);
			setVisible(true);
			this.setTitle("Alta de Rodamiento");
			getContentPane().setLayout(null);
			{
				btnCancelar = new JButton();
				getContentPane().add(btnCancelar);
				btnCancelar.setText("Cancelar");
				btnCancelar.setBounds(224, 247, 111, 26);
				btnCancelar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						dispose();
					}
				});
			}
			{
				btnAceptar = new JButton();
				getContentPane().add(btnAceptar, "Center");
				btnAceptar.setText("Aceptar");
				btnAceptar.setBounds(88, 247, 111, 26);
				btnAceptar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						BeanRodamiento beanRodamiento = new BeanRodamiento();
						beanRodamiento.setCodigo(txtCodigo.getText());
//						beanRodamiento.setBeanMarca((BeanMarca)jComboMarcas.getSelectedItem());
						BeanMarca bMarca = new BeanMarca();
						bMarca.setDescripcion("Desc1");
						bMarca.setId(1);
						bMarca.setPais("Argentina");
						beanRodamiento.setBeanMarca(bMarca);
//						beanRodamiento.setCaracteristicas((String)jComboMarcas.getSelectedItem());
						beanRodamiento.setCaracteristicas(txtCaracteristica.getText());
						beanRodamiento.setTipo(txtTipo.getText());
						beanRodamiento.setMedida(txtMedida.getText());
						boolean result = controllerPrincipal.getInstancia().altaRodamiento(beanRodamiento);
					
						if (result)
							JOptionPane.showMessageDialog(JInternalFrameAltaRodamiento.getInstancia(),"Grabe ok :D");
						else
							JOptionPane.showMessageDialog(JInternalFrameAltaRodamiento.getInstancia(),"Grabe MAL :(");
						}
					}
				);
			}
			{
				lblCodigo = new JLabel();
				getContentPane().add(lblCodigo);
				lblCodigo.setText("Codigo: ");
				lblCodigo.setBounds(45, 38, 110, 14);
			}
			{
				lblMarca = new JLabel();
				getContentPane().add(lblMarca);
				lblMarca.setText("Marca: ");
				lblMarca.setBounds(46, 148, 110, 14);
			}
			{
				txtCodigo = new JTextField();
				getContentPane().add(txtCodigo);
				txtCodigo.setBounds(173, 34, 176, 21);
			}
			{
				lblCaracteristica = new JLabel();
				getContentPane().add(lblCaracteristica);
				lblCaracteristica.setText("Tipo:");
				lblCaracteristica.setBounds(46, 71, 110, 14);
			}
			{
				txtTipo = new JTextField();
				getContentPane().add(txtTipo);
				txtTipo.setBounds(173, 66, 176, 21);
			}
			{
				txtCaracteristica = new JTextField();
				getContentPane().add(txtCaracteristica);
				txtCaracteristica.setBounds(174, 105, 176, 21);
			}
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("Caracteristica: ");
				jLabel1.setBounds(46, 109, 110, 14);
			}
			{
				ComboBoxModel jComboBox1Model = 
						new DefaultComboBoxModel(
								new String[] {});
				jComboMarcas = new JComboBox();
				getContentPane().add(jComboMarcas);
				jComboMarcas.setModel(jComboBox1Model);
				jComboMarcas.setBounds(174, 145, 176, 21);
			}
			
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setText("Medida: ");
				jLabel2.setBounds(46, 196, 110, 14);
			}
			{
				txtMedida = new JTextField();
				getContentPane().add(txtMedida);
				txtMedida.setBounds(174, 193, 176, 21);
			}
			cargarMarcas();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
